<?php
$base_url = site_url();
?>

<?php
foreach ($alerts as $alert) {
    echo '<div class="alert alert-danger">' . $alert->ARTICLE_REF . ' (' . $alert->ARTICLE_LIBELLE . ') : Stock insuffisant (' . $alert->STOCK . '), le seuil minimal est de ' . $alert->ARTICLE_SEUIL . ' </div>';
}
?>

<a href="<?php echo $base_url . 'matiere_premiere/create'; ?>" class="btn create" >Nouveau</a>   
<!--<a class="btn order" >Commander</a>-->
<input type="hidden" id="base_url" value="<?php echo $base_url; ?>" />
<table class="table table-striped" id="liste_matiere_premiere">
    <thead>
        <tr>
            <th>Reférence</th>
            <th>Libellé</th>
            <th>Unité</th>
            <th>Stock</th>
            <th>Retirer</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <?php
        foreach ($matiere_premieres as $mp) {
            $url_Update = $base_url . 'matiere_premiere/update?ARTICLE_ID=' . $mp->ARTICLE_ID;
            $url_Delete = $base_url . 'matiere_premiere/delete?ARTICLE_ID=' . $mp->ARTICLE_ID;
            $url_Addstock = $base_url . 'stock/addstock/' . $mp->ARTICLE_ID;
            $url_Removestock = $base_url . 'stock/removestock/' . $mp->ARTICLE_ID;
            $url_Constituer = $base_url . 'matiere_premiere/fournir/' . $mp->ARTICLE_ID;
            ?>
            <tr id="<?php echo $mp->ARTICLE_ID ?>">
                <td><?php echo $mp->ARTICLE_REF ?></td>
                <td><?php echo $mp->ARTICLE_LIBELLE ?></td>
                <td><?php echo $mp->UNITE_CODE ?></td>
                <td><?php echo $mp->STOCK ?><input type="hidden" name="STOCK" value="<?php echo $mp->STOCK ?>" /></td>
                <td>
                    <input type="number" min="0" value="0" max="<?php echo $mp->STOCK ?>" class ="input-small" name="RET_STOCK" />
                    <a href="<?php echo $url_Removestock; ?>" class="btn remove-from-stock"> Retirer</a>
                </td>
                <td>
                    <a href="<?php echo $url_Addstock; ?>" class="btn add-in-stock"> Ajout stock</a>
                    <a href="<?php echo $url_Update; ?>" class="btn update"> Modifier</a>
                    <a href="<?php echo $url_Delete; ?>" class="btn delete"> Supprimer</a>
                    <!--<a href="<?php echo $url_Constituer; ?>" class="btn constituer"> Fournisseur</a>-->
                </td>
            </tr>
            <?php
        }
        ?>
    </tbody>
</table>

<div class="dialog" style="display: none;"></div>
<!--
<script>
    $(document).ready(function() {
        $('a.constituer').on('click', function(e) {
            e.preventDefault();
            $('div.dialog').dialog({
                title:'Fournisseurs',
                autoOpen:false,
                width: 1000,
                height: 'auto',
                modal:true,
                buttons: {
                    'Valider' : function(e) {
                        constituer($(this).attr('href'));
                    },
                    'Annuler' : function(e) {
                        $(this).dialog('close');
                    }
                }
            })
            .load($(this).attr('href'));
            $('div.dialog').dialog('open');
        })
    });
    
    function constituer(url) {
        $.ajax({
            url : url,
            type: 'POST',
            data : {
                fournisseur: $('select.selectFournisseur').val()
            },
            success : function(e) {
                $(location).attr('href', $(location).attr('href'));
            }
        });
    }
</script>
-->